<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        // var x = 9;
        // x = null;
        // console.log(typeof x);
        var colorTr = null;
        window.onload = function () {
            var trArray = document.getElementById("data").getElementsByTagName("tr");
            for(var i=0;i<trArray.length;i++){
                trArray[i].onclick = function () {
                    trClick(this);
                }
            }
        }

        function trClick(trObj) {
            if(colorTr != null){
                colorTr.style.backgroundColor = "white";
            }
            trObj.style.backgroundColor = "red";
            colorTr = trObj;
        }
    </script>
</head>
<body>
    <table border="1" cellspacing="0" width="50%">
        <thead>
            <tr><th>姓名</th><th>性别</th><th>电话</th></tr>
        </thead>

        <tbody id="data">
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
            <tr><td>张三</td><td>男</td><td> 1302938274</td></tr>
        </tbody>
    </table>
</body>
</html>